<?php
/**
 * Created by PhpStorm.
 * User: sl
 * Date: 17-6-24
 * Time: 下午7:18
 */

namespace ActionsHttp;

use Data\Tree_customer_info_DAO;

class CustomerLoginState extends BaseActionHttp
{
    public function doAction()
    {
        $customer_id_random_str = $this->data[CUSTOMER_ID];
        $customer_id = substr($customer_id_random_str, 10);
        // 检测登陆是否过期
        $customer_record = Tree_customer_info_DAO::getRecord($customer_id);
        if (!$customer_record) {
            $this->setValue('login_state',0);
            $this->ResponseDataToCurrentClient();
        }
        $customer_login_time = $customer_record->getLOGIN_TIME();

        if ($customer_login_time && (time() - $customer_login_time < SESSION_VALID_TIME)) {
            // 有效时间内
            $customer_record->setLOGIN_TIME(time());
            Tree_customer_info_DAO::update($customer_record);
            $this->setValue('login_state', 1);
            $this->ResponseDataToCurrentClient();
        } else {
            // 无效
            $this->setValue('login_state', 0);
            $this->ResponseDataToCurrentClient();
        }
    }
}